package com.foo.SnapshotDataProvider;

import com.foo.DataProvider.*;
import java.sql.Date;
import java.sql.Timestamp;

import javax.ejb.Stateless;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.foo.DAO.SnapshotTemporalDAO;
import com.foo.DAO.SpatialDAO;
import com.foo.DataSender.DataSender;
import com.foo.Entity.HistoricalData;
import com.foo.Entity.TickerInfoData;

/**
 * Session Bean implementation class SnapshotDataProvider
 */
@Stateless
public class SnapshotDataProvider implements ProviderInterface{ // SnapshotDataProviderRemote, SnapshotDataProviderLocal 
	int total =0 ;
	String snapshotmessage = ""; 
	DataSender datasender = new DataSender();
    public SnapshotDataProvider() 
    {
    	System.out.println("Snapshot Data Provider created!"); 
    }
    
		
	
	@Override
	public void getData(String sorttype, String value, Timestamp timestamp, Date fromdate, Date todate)
	{		
		System.out.println("Entering server function Snapshot Data with parameters " +sorttype + " " +value);

		System.out.println("Server side: if condition :");
		// Example for using named query
		snapshotmessage = ""; 
		ApplicationContext context = new ClassPathXmlApplicationContext("/beans.xml");
		SnapshotTemporalDAO forumDAO = (SnapshotTemporalDAO) context.getBean("snapshotDAO");   		
		HistoricalData[] datalist=forumDAO.selectForum(sorttype, fromdate, todate);		
	
		if(datalist != null)
		{
		for(int k=0 ; k< datalist.length ; k++)
		{
			snapshotmessage += datalist[k].getTicker_symbol()+","+datalist[k].getDeals_date()+","+ datalist[k].getOpen_value() +"," +datalist[k].getHigh_value() 
			+","+datalist[k].getLow_value()+ ","+datalist[k].getClose_value()+","+datalist[k].getVolume()+",";
		}
		}
		else
		{
			snapshotmessage="";
		}
		
	System.out.println("The message " +snapshotmessage);
	datasender.sendMessage("Snapshot",snapshotmessage);
	}
}
